<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tab-box{
            display: inline-flex;
            flex-direction: column;
            border: 1px solid black;            
        }
        .tab-header{
            display: flex;
        }
        .tab-header-div{
            width: 100px;
            height: 30px;
            background-color: gray;
            color: black;
            text-align: center;
            line-height: 30px;
        }
        .r{
            border-right: 1px solid white;
        }
        .tab-body-div{
            width: 300px;
            height: 200px;
            display: none;
        }
        .tab-header .current{
            background-color: white;
            color: black;
        }
        .tab-body .current{
            display: block;
        }
    </style>
</head>
<body>
    <div class="tab-box">
        <div class="tab-header">
            <div class="tab-header-div r current">标签一</div>
            <div class="tab-header-div r">标签二</div>
            <div class="tab-header-div r">标签三</div>
        </div>
        <div class="tab-body">
            <div class="tab-body-div current">body1</div> 
            <div class="tab-body-div">body2</div>
            <div class="tab-body-div">body3</div>
        </div>
    </div>
     <script>
        //获取title数组
        var titleArr = document.querySelectorAll(".tab-header-div");
        //获取body数组
        var bodyArr=document.querySelectorAll(".tab-body-div");
        titleArr.forEach((ele,index)=>{
            //鼠标悬停事件
            ele.onmouseover=function(e){
                //对title移除current样式
                titleArr.forEach(ele=>ele.classList.remove("current"));
                //对body移除current样式
                bodyArr.forEach(ele=>ele.classList.remove("current"));
                //对悬停对象增加current样式
                e.target.classList.add("current");
                //对悬停对象对应的body增加current样式
                bodyArr[index].classList.add("current");
            }
        });
     </script>
</body>
</html>